/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.permission.controller;

/**
 *
 * @author ems
 */
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import queenb.web.util.SessionProvider;
import queenb.net.entitybean.N100;
import queenb.net.entitybean.Q150;
import queenb.web.controller.QueenbController;
import queenb.web.crm.store.CustomerStore;
import queenb.web.inteface.EmployeeInf;
import queenb.web.permission.store.Q150Store;
import queenb.web.store.EmployeeStore;

public class Q175Controller extends QueenbController {

    /**
     * @return the logger
     */
    public static Logger getLogger() {
        return logger;
    }

    /**
     * @param aLogger the logger to set
     */
    public static void setLogger(Logger aLogger) {
        logger = aLogger;
    }
    private int flag;
    private String permission = "";
    private int PQ100;
    private int PQ400;
    private int value;
    private String keySearch;
    private int fn450;
    private int fn850;
    private int fh200;
    private EmployeeInf empInf;
    private int typeSearch = 0;
    private EmployeeStore employeeStore;
    private static Logger logger = Logger.getLogger(Q175Controller.class);

    public Q175Controller() {
        getKapiMenu().setAdmin(true);
        getKapiMenu().setMainmenu2("m222");
        employeeStore = new EmployeeStore();
        Object pn100 = getRequest().getParameter("pn100");
        if (pn100 != null) {
            PQ100 = Integer.parseInt(pn100.toString());

        }


    }

    public List<N100> getAllListN100() {

        List<N100> listEmployee = new ArrayList<N100>();
        try {

            if (SessionProvider.getSessionMapValue("submitSearch") != null && SessionProvider.getSessionMapValue("submitSearch").toString().equals("true")) {
                setTypeSearch(0);
            }
            if (getKeySearch() != null && getKeySearch().contains("Nhập từ khóa")) {
                setKeySearch(getLogin().getCharacter());
            }
            if (getTypeSearch() == 1) {
                System.out.println("---------------KEY SEARCH MOBI-----------" + keySearch + "--fn450--:" + fn450 + "--fn850--:" + fn850);
                listEmployee = empInf.getListComN100Mobile(getLogin().getModule(), getLogin().getCompanyNo(), fn450, fn850, keySearch,0,100,0,1, getLogin().getUserName());
            } else if (getTypeSearch() == 2) {
                System.out.println("---------------KEY SEARCH NAME-----------" + keySearch + "--fn450--:" + fn450 + "--fn850--:" + fn850);
                listEmployee = empInf.getListComN100Name(getLogin().getModule(), getLogin().getCompanyNo(), fn450, fn850, keySearch,0,100,0,1, getLogin().getUserName());
            } else if (getTypeSearch() == 3) {
                System.out.println("---------------KEY SEARCH PASS-----------" + keySearch + "--fn450--:" + fn450 + "--fn850--:" + fn850);
                listEmployee = empInf.getListComN100Passport(getLogin().getModule(), getLogin().getCompanyNo(), fn450, fn850, keySearch,0,100,0,1, getLogin().getUserName());

            } else if (getTypeSearch() == 4) {
                System.out.println("---------------KEY SEARCH EMAIL-----------" + keySearch + "--fn450--:" + fn450 + "--fn850--:" + fn850);
                listEmployee = empInf.getListComN100Email(getLogin().getModule(), getLogin().getCompanyNo(), fn450, fn850, keySearch,0,100,0,1, getLogin().getUserName());
            } else if (getTypeSearch() == 0) {
                System.out.println("---------------KEY SEARCH ALL-----------" + keySearch + "--fn450--:" + fn450 + "--fn850--:" + fn850 + "---getLogin().getId()--" + getLogin().getId());

                listEmployee = employeeStore.getAllListTabN100All(getLogin().getModule(), getLogin().getCompanyNo(), 0, fn450, fn850,0, keySearch,0,100,0,1, getLogin().getUserName());

            }


        } catch (Exception e) {

            System.out.println("ERROR-------------N100-" + e.getMessage());
        }
        if (listEmployee == null) {
            listEmployee = new ArrayList<N100>();
        }        
        return listEmployee;



    }

    /**
     * @return the flag
     */
    public int getFlag() {
        Object oid = getRequest().getParameter("id");
        Object ovalue = getRequest().getParameter("value");
        if (oid != null && ovalue != null) {
            value = Integer.parseInt(ovalue.toString());
            String[] arr = oid.toString().split("--");
            PQ400 = Integer.parseInt(arr[0]);
            PQ100 = Integer.parseInt(arr[1]);

            CustomerStore store = new CustomerStore();
            store.update2Column(null, "Q175", "QN176", value, "FQ400", PQ400, "FN100", PQ100, getLogin().getUserName());
            System.out.println("--------------->" + value + PQ100 + PQ400);

        }

        return flag;
    }

    /**
     * @param flag the flag to set
     */
    public void setFlag(int flag) {
        this.flag = flag;
    }

    /**
     * @return the permission
     */
    public String getPermission() {
        Q150Store store = new Q150Store();
        List<Q150> list = new ArrayList<Q150>();

        try {
            System.out.println("------- tham so truyen vao ---"+ getLogin().getModule()+ 0+ 0+ PQ100);
            list = store.findQ175(getLogin().getModule(), 0, 0, PQ100);
            System.out.println("sizeê" + list.size() + "--" + PQ100);
        } catch (Exception ex) {
            System.out.println("error" + ex.getMessage());
        }
        int j = 0;
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {

                if (i == 0 || list.get(i).getFq300() != list.get(i - 1).getFq300()) {
                    j++;
                    if (i != 0) {
                        permission += "</div>";
                    }
                    if (j % 2 == 0) {
                        permission += "<div onclick='expand(this)' style='background-color: #E0EFFC'  class='group '>" + getResourceString(list.get(i).getQv301()) + "</div>";
                    } else {
                        permission += "<div onclick='expand(this)'   class='group '>" + getResourceString(list.get(i).getQv301()) + "</div>";
                    }

                    permission += "<div style='display:none' class='child '>";
                }
                if (i % 2 == 0) {
                    permission += "<div class='destinationItem ' style='background-color: #F0F6FC' >";
                } else {
                    permission += "<div class='destinationItem '  >";
                }

                permission += getResourceString(list.get(i).getQv179());
                String checked = "";
                if (list.get(i).getQn176() == 1) {
                    checked = "checked='checked'";
                }
                permission += "<input class='checkbox' type='checkbox' " + checked + " lang='" + list.get(i).getFq400() + "--" + PQ100 + "' />";
                permission += "</div>";
            }
            permission += "</div>";
        }
        return permission;
    }

    /**
     * @param permission the permission to set
     */
    public void setPermission(String permission) {
        this.permission = permission;
    }

    /**
     * @return the PQ100
     */
    public int getPQ100() {
        return PQ100;
    }

    /**
     * @param PQ100 the PQ100 to set
     */
    public void setPQ100(int PQ100) {
        this.PQ100 = PQ100;
    }

    /**
     * @return the PQ400
     */
    public int getPQ400() {
        return PQ400;
    }

    /**
     * @param PQ400 the PQ400 to set
     */
    public void setPQ400(int PQ400) {
        this.PQ400 = PQ400;
    }

    /**
     * @return the value
     */
    public int getValue() {
        return value;
    }

    /**
     * @param value the value to set
     */
    public void setValue(int value) {
        this.value = value;
    }

    /**
     * @return the keySearch
     */
    public String getKeySearch() {
        return keySearch;
    }

    /**
     * @param keySearch the keySearch to set
     */
    public void setKeySearch(String keySearch) {
        this.keySearch = keySearch;
    }

    /**
     * @return the typeSearch
     */
    /**
     * @param typeSearch the typeSearch to set
     */
    public void setTypeSearch(int typeSearch) {
        this.typeSearch = typeSearch;
    }

    /**
     * @return the typeSearch
     */
    public int getTypeSearch() {
        return typeSearch;
    }
}